package org.yn.auth.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yn.auth.domain.Menu;
import org.yn.auth.dto.MenuDTO;
import org.yn.auth.mapper.MenuMapper;
import org.yn.auth.service.IMenuService;
import org.yn.base.service.impl.BaseServiceImpl;
import org.yn.base.util.PageInfo;
import org.yn.query.MenuQuery;

import java.util.List;
@Service
public class MenuServiceImpl extends BaseServiceImpl<Menu> implements IMenuService {
    @Autowired
    MenuMapper menuMapper;


    @Override
    public PageInfo<Menu> queryPage(MenuQuery menuQuery) {
        Integer total =menuMapper.countTotal(menuQuery);
        if (total==0){
            return new PageInfo<Menu>();//返回一个空的
        }
        //查询分页数据
        List<Menu> list= menuMapper.queryPage(menuQuery);

        return new PageInfo<Menu>(total, list);
    }


    @Override
    public void insertByMenuId(MenuDTO menuDTO) {
        //删除该菜单的角色
        menuMapper.deleteByMenuId(menuDTO.getMenuId());
        //保存新的
        menuMapper.insertByRoleId(menuDTO);
    }

    @Override
    public List<Long> selectByMenuId(Long id) {

        return menuMapper.selectByMenuId(id);
    }

    @Override
    public List<Menu> queryMenuTree(Long id) {
        return menuMapper.queryMenuTree(id);
    }


    @Override
    public List<Menu> queryParentMenuList() {
        return menuMapper.queryParentMenuList();
    }
}
